<template>
  <div class="wrap">
    <div class="header">
      <div class="left">
        <div class="search-item">
          <el-select
            v-model="queryParams.payType"
            placeholder="$t('table.rechargeRecord.请选择')"
            size="small"
            class="header-select mgb10"
            @change="changeOption"
            clearable
          >
            <el-option :label="$t('table.rechargeRecord.全部充值方式')" value=""></el-option>
            <el-option
              v-for="item in payTypeList"
              :key="item.type"
              :label="item.name"
              :value="item.type"
            ></el-option>
          </el-select>
          <el-date-picker
            v-model="queryParams.createTimes"
            type="daterange"
            class="mgr20 mgb10"
            :start-placeholder="$t('table.rechargeRecord.（创建）开始时间')"
            :end-placeholder="$t('table.rechargeRecord.结束时间')"
            value-format="yyyy-MM-dd"
            @change="changeOption"
          >
          </el-date-picker>
        </div>
      </div>
      <div class="right">
        <div style="display: inline-block; width: 300px;">
          <el-input
            size="small"
            style="width: 200px; margin-right: 10px; margin-bottom: 10px"
            v-model="queryParams.keyword"
            :placeholder="$t('table.rechargeRecord.搜索 用户名/充值单号')"
            @keyup.enter.native="changeOption(true)"
            clearable @clear="changeOption(false, 'clear')"
          ></el-input>
          <el-button size="small" type="primary" @click="changeOption(true)">{{ $t('common.search') }}</el-button>
        </div>
      </div>
    </div>
    <div class="content">
      <div class="page-wrap">
        <el-table
          v-loading="loading"
          :data="data"
          border
          v-tableHeight="{bottomOffset: 80}"
          height="100px"
          ref="tableData"
        >
          <el-table-column
            prop="userName"
            :label="$t('table.rechargeRecord.充值用户')"
            align="center"
            min-width="100"
          >
            <template slot-scope="{row}">
              <diy-link @click="jumpInfo(row)">{{row.userName}}</diy-link>
            </template>
          </el-table-column>
          <el-table-column
            prop="createTime"
            :label="$t('table.rechargeRecord.创建时间')"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="payPredictAmount"
            :label="$t('table.rechargeRecord.充值金额（元）')"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="amount"
            :label="$t('table.rechargeRecord.到账金额（元）')"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="type"
            :label="$t('table.rechargeRecord.充值方式')"
            align="center"
            min-width="100"
          >
            <template slot-scope="{row}">
              <template v-if="row.rechargeType == 2">
                {{getPayTypeStr(row.type)}}(手动)
              </template>
              <template v-else>
                {{getPayTypeStr(row.type)}}
              </template>
            </template>
          </el-table-column>
          <el-table-column
            prop="orderId"
            :label="$t('table.rechargeRecord.充值单号')"
            align="center"
            min-width="100"
          >
          </el-table-column>
          <el-table-column
            prop="payArrivalStatus"
            :label="$t('table.rechargeRecord.充值状态')"
            align="center"
            min-width="100"
          >
          </el-table-column>
        </el-table>
        <el-pagination
          class="mgt10"
          @current-change="getData"
          :current-page.sync="queryParams.page"
          :page-size="queryParams.pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          :page-sizes="[20, 50, 100]"
          @size-change="handleSizeChange"
        >
        </el-pagination>
      </div>
    </div>

  </div>
</template>

<script>
import {getRechargeRecordData} from "@/api/user";
import {getPayTypeList, getPayTypeStr} from "@/utils";

export default {
  name: "rechargeRecord",
  data(){
    return {
      queryParams:{
        page: 1,
        pageSize: 20,
        keyword: '',
        payType: '',
        createTimes: '',
      },
      data: [],
      payTypeList: [],
      loading: false,
      total: 0,
      is_search: false,
    }
  },
  created() {
    this.getData()
    this.payTypeList = getPayTypeList()
  },
  updated () {
    this.$nextTick(() => {
      this.$refs['tableData'].doLayout();
    })
  },
  methods: {
    getPayTypeStr,
    getPayTypeList,
    getData(){
      this.loading = true
      getRechargeRecordData(this.queryParams)
        .then(res=>{
          this.loading = false
          this.data = res.data
          this.total = res.info.total
        })
    },
    handleSizeChange(pageSize){
      this.queryParams.pageSize = pageSize
      this.queryParams.page = 1
      this.getData()
    },
    jumpInfo(row){
      this.$router.push({
        name: 'userInfo',
        query: {
          id: row.userID
        }
      })
    },
    changeOption(is_search = false, type = ''){
      if (is_search == true) {
        //判断是否使用过搜索按钮
        this.is_search = true
      }
      if (type == 'clear') {
        if (this.is_search == false) {
          return
        } else {
          this.is_search = false
        }
      }
      this.queryParams.page = 1;
      this.getData()
    },
  },
}
</script>

<style scoped lang="scss">
.wrap {
  padding: 30px 30px;
  .header{
    display: flex;
    justify-content: space-between;
  }
  .content{
    padding: 20px 0 0;
  }

}
.header-select{
  margin-right: 20px;
}
.form-tips{
  font-size: 12px;
}
</style>
